package com.leyou.item.controller;

import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询分类集合
     * @RequestParam("pid")  form表单数据 一般可以省略 如果涉及到fegin调用，也不能省略，尽量不要省略
     * @PathVariable  rest风格占位符中的数据
     * @RequestBody  json数据
     */
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<Category>> findCategoryByPid(@RequestParam("pid") Long pid){
        List<Category> list = categoryService.findCategoryByPid(pid);
        return ResponseEntity.ok(list);
        //return ResponseEntity.status(HttpStatus.OK).body(list);
    }

    /**
     * 根据分类id的集合批量查询分类对象
     */
    @GetMapping("/category/list")
    public ResponseEntity<List<Category>> findCategoriesByIds(@RequestParam("ids") List<Long> ids){
        List<Category> categoryList = categoryService.findCategoriesByIds(ids);
        return ResponseEntity.ok(categoryList);
    }

}
